package com.bolinfest.editor.util;

import java.util.Set;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;

public final class JsonUtil {

  /** Utility class: do not instantiate. */
  private JsonUtil() {}

  /**
   * Takes a set of strings, and returns a string of JSON which defines an
   * object literal whose keys are the elements in the set and whose values
   * are the boolean <code>true</code>.
   * If the input were:
   * <pre>ImmutableSet.of("apple", "banana", "orange")</pre>
   * then the return value would be:
   * <pre>"{\"apple\": true, \"banana\": true, \"orange\": true}"</pre>
   */
  public static String serialialzeSet(Set<String> strings) {
    JsonObject json = new JsonObject();
    JsonElement trueElement = new JsonPrimitive(true);
    for (String s : strings) {
      json.add(s, trueElement);
    }
    return json.toString();
  }
}
